package com.telsoft.data;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.List;

import com.telsoft.business.DAOHelperBusiness;
import com.telsoft.entity.ComponentEntity;

public class ComponentDAO {
	public List<ComponentEntity> getComponent() throws SQLException {
		List<ComponentEntity> components = new Vector<ComponentEntity>();
		Connection conn = DAOHelperBusiness.getConnection();
		Statement stm = DAOHelperBusiness.getStatement(conn);
		String sqlQuery = "SELECT * FROM COMPONENT";
		ResultSet rs = stm.executeQuery(sqlQuery);
		while (rs.next()) {
			ComponentEntity component = new ComponentEntity();
			component.setComID(rs.getInt("COM_ID"));
			component.setGrComID(rs.getInt("GRCOM_ID"));
			component.setName(rs.getString("NAME"));
			component.setDetDail(rs.getString("DETAIL"));
			component.setDateUpdate(rs.getDate("DATE_UPDATE"));
			component.setType(rs.getBoolean("TYPE"));
			components.add(component);
		}
		DAOHelperBusiness.closeStatement(stm);
		DAOHelperBusiness.closeConnection(conn);
		return components;
	}
}
